// TOWN SCRIPT
//    Town 2: Cresent Harbor

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 2, 5 = read note about Avernum passage...
// 2, 6 = can talk to mayor
// 2, 8 = switch Georgia dialog start nodes...
//  2, 9 and 2, 10 Georgia encounter flags
// 2, 13 = number of horses sold (have 3 available)
// 2, 14 = trap
// 2, 15 = gave coins to begger (count of how many you've given)
// 2, 16 = already asked stan what he does
// 2, 17 / 2, 18 = mayor clune conversation flags
// 2, 19 = note sent to Henner
// 2, 20 = farthest notified you are asking questions
// 2, 24 = asked clay what he does

begintownscript;

variables;

short i, choice;

body;

beginstate INIT_STATE;
	set_crime_tolerance(5);

	set_name(6, "Mayor Clune");
	set_char_dialogue_pic(6, 1962, 0);
	set_name(7, "Ivan");
	set_char_dialogue_pic(7, 1956, 0);
	set_name(8, "Georgia");
	set_char_dialogue_pic(8, 532, 0);
	set_name(11, "PurrFly");
	set_char_dialogue_pic(11, 1953, 0);
	set_name(12, "Clairesse");
	set_char_dialogue_pic(12, 533, 0);
	set_name(14, "Stan");
	set_char_dialogue_pic(14, 537, 0);
	set_name(19, "Begger");
	set_char_dialogue_pic(19, 539, 0);
	set_name(31, "Clay");
	set_char_dialogue_pic(31, 542, 0);
	set_name(32, "Nancy");
	set_char_dialogue_pic(32, 541, 0);
	set_name(37, "Father Ian");
	set_char_dialogue_pic(37, 543, 0);

	// remove begger (Henner) from town (gave him 10 coins or note sent)
	if ((get_flag(2, 15) > 9) || (get_flag(2, 19) > 0)) {
		erase_char(19);
	}

	// reset temple sign
	set_flag(2, 25, 0);

	// remove spider from warehouse (if not dead) - may spawn later
	if (get_flag(2, 12) == 0) {
		erase_char(9);
	}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	if (get_ran(1, 0, 100) < 8) {
		i = get_ran(1, 1, 7);
		if (i == 1)
			text_bubble_on_char(10, "Old McDonald had a Farm");
		if (i == 2)
			text_bubble_on_char(10, "E-eye, E-eye, Oh");
		if (i == 3)
			text_bubble_on_char(10, "On that farm he had a cow");
		if (i == 4)
			text_bubble_on_char(10, "With a moo moo here");
		if (i == 5)
			text_bubble_on_char(10, "And a moo moo there");
		if (i == 6)
			text_bubble_on_char(10, "Here a moo, there a moo");
		if (i == 7)
			text_bubble_on_char(10, "Everywhere a moo moo");
	}
	if ((get_flag(2, 19) == 0) && (get_ran(1, 0, 100) < 6)) {
		text_bubble_on_char(19, "Spare a few coins.");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(24, "Your move.");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(25, "Now its your move.");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(27, "Meow");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(28, "Woof");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(30, "Move along now!");
	}
	if (get_ran(1, 0, 100) < 10) {
		i = get_ran(1, 0, 100);
		if (i <= 33)
			text_bubble_on_char(36, "Oh Gork, my Gork.");
		else if (i >= 66)
			text_bubble_on_char(36, "Where art thou Gork.");
		else
			text_bubble_on_char(36, "I will avenge thee Gork.");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(37, "Bless you.");
	}
break;

beginstate 10;
	message_dialog("Waves lap up gently against the tar covered pilings at the end of the dock.", "The bustling trade that used to ply these docks is gone with the empire quarantine.");
break;

beginstate 11;
	if (get_flag(2, 0) == 0) {
		set_flag(2, 0, 1);
		message_dialog("With no ships and no goods moving though the port, the warehouse is empty.", "Your footsteps echo hollowly in the dust on the floor.");
	}
break;

beginstate 12;
	if (get_flag(2, 1) == 0) {
		set_flag(2, 1, 1);
		message_dialog("As you walk through the empty warehouse, you kick up a cloud of dust.", "You all sneeze, awaking some sleeping inhabitants of the warehouse.");
		place_monster(52, 12, 72, 0);
		place_monster(50, 10, 72, 0);
		place_monster(53, 12, 176, 0);
	}
break;

beginstate 13;
	if (get_flag(2, 3) == 0) {
		set_flag(2, 3, 1);
		message_dialog("Mmmmm.  You seemed to have found Cresent Harbor's treasury.", "Most of the villages rainy day money is here which they are depending on during this time of crisis.");
		if (get_highest_skill(24) >= 9) {
			message_dialog("Your pathfinding skills let you know that the floor to the chest is magically charged.", "You will take damage if you go any further.");
		}
		else {
			message_dialog("It looks as if there is nothing between you and the treasure.", "If you are callous enough to go take it.");
		}
	}
break;

beginstate 14;
	if (get_flag(2, 4) == 0) {
		set_flag(2, 4, 1);
		message_dialog("The records for Cresent Harbor and surrounding region are stored here.", "It doesn't look like you'll find anything useful in the dusty piles of paper.");
	}
break;

beginstate 15;
	message_dialog("Behind a pile of notebooks about the region, you find a note about the 'Avernum passage'", "You wonder if perhaps there is a passage around here through to Avernum.");
	set_flag(2, 5, 1);
break;

beginstate 16;
	if (get_flag(2, 6) == 0) {
		play_sound(18);
		message_dialog("You hear the sliding of steel behind you and a gruff voice asking _Where are you going?_", "_You need to sign in first before talking to the mayor._");
		block_entry(1);
	}
	else {
		block_entry(0);
	}
break;

beginstate 17;
	reset_dialog();
	add_dialog_str(0, "Georgia has a large number of books in her bookcase.", 0);
	add_dialog_str(1, "Besides the usual racey novels you expect to find, you are surprised to see she has many self improvement books, instruction manuals and learned tomes in the collection.", 0);
	add_dialog_str(2, "You briefly leaf through a book on the medical procedures of dwarves before putting the book back on the shelf.", 0);
	add_dialog_choice(0, "OK");
	choice = run_dialog(1);
break;

beginstate 18;
	if (get_flag(2, 7) == 0) {
		set_flag(2, 7, 1);
		message_dialog("Stuffed behind a stack of ancient invoices, you find a folded scrap of paper.", "When you unfold it, you are pleasantly surprised to find the paper contains the recipe for creating a restoration brew.");
		give_recipe(13);
	}
break;

beginstate 19;
	if (get_flag(2, 8) > 0) {
		set_flag(2, 8, 0);
		block_entry(1);
		erase_char(8);
		reset_dialog();
		add_dialog_str(0, "Georgia meets you at the door of her house.  She blocks the door as you try to enter.", 0);
		add_dialog_str(1, "_My price is 75 coins and only one can enter at a time._ she says", 0);
		add_dialog_str(2, "She adds _I can guarentee that you will get what you need._", 0);
		add_dialog_choice(0, "Agreed");
		add_dialog_choice(1, "I'm out of here");
		choice = run_dialog(0);
		if (choice == 2) {
			message_dialog("Georgia smiles at you saying _Maybe some other time then._", "She leaves and heads back out to the street.");
			spawn_creature(8);
			end();
		}
		if (run_select_a_pc(0) > 0) {
			if (pay_coins(75) > 0) {
				swap_terrain(41, 40, 498, 500);
				set_flag(2, 9, 1);
				play_sound(39);
				message_dialog("Georgia takes the coins and the hand of the lucky one and heads back towards the bedroom.", "");
				split_off_one_char(39, 40, 0, get_selected_pc());
				message_dialog("_Come and join me on the bed._ Georgia says.", "");
			}
			else {
				message_dialog("Georgia says _You don't have enough coins right now._", "_Come back and see me when you do._ she says with a sexy smile before heading back to the street.");
				spawn_creature(8);
			}
		}
		else {
			message_dialog("Georgia smiles at you and heads back out into the street.", "_Maybe next time then._ she says as she passes you.");
			spawn_creature(8);
		}
	}
	else {
		block_entry(0);
	}
break;

beginstate 20;
	if (get_flag(2, 9) > 0) {
		block_entry(1);
		set_flag(2, 9, 0);
		set_flag(2, 10, 1);
		message_dialog("Time passes as you join Georgia on the bed.", "In addition, your question about what she has that you need is answered.");
		set_ticks_forward(200);
	}
break;

beginstate 21;
	block_entry(0);
	if (get_flag(2, 10) > 0) {
		if (get_flag(2, 9) > 0) {
			reset_dialog();
			add_dialog_str(0, "Georgia calls out grabing your hand _Wait, you haven't got what you paid for yet._", 0);
			add_dialog_str(1, "_Are you sure you want to go?_ she says looking deep within your eyes.", 0);
			add_dialog_choice(0, "Yes");
			add_dialog_choice(1, "No");
			choice = run_dialog(0);
			if (choice == 1) {
				message_dialog("Georgia says pouting _OK, maybe next time._", "She lets you go as you return to your companions.");
			}
			else {
				message_dialog("_Well then, come join me on the bed._", "");
				block_entry(1);
				end();
			}
		}
		else {
			message_dialog("You head back to join your companions feeling a lot better.", "And very relaxed...");
			restore_pc(get_selected_pc());
		}
		set_flag(2, 9, 0);
		set_flag(2, 10, 0);
		reunite_party();
		spawn_creature(8);
		swap_terrain(41, 40, 498, 500);
		block_entry(1);
	}
break;

beginstate 22;
	if (get_flag(2, 11) == 0) {
		set_flag(2, 11, 1);
		message_dialog("This warehouse is as empty as all of the warehouses in Cresent Harbor.", "A thin layer of dust coats everything.");
	}
break;

beginstate 23;
	if (get_flag(2, 12) == 0) {
		set_flag(2, 12, 1);
		message_dialog("Another empty warehouse along the docks of Cresent Harbor.", "Your feet kick up puffs of dust from the floor as you walk in and awakes an inhabitant in the corner.");
		spawn_creature(9);
	}
break;

beginstate 24;
	message_dialog("The shelves contain a variety of foodstuffs and bottles of brew.", "There is nothing of interest on the shelves.");
break;

beginstate 25;
	if (get_flag(2, 21) == 0) {
		set_flag(2, 21, 1);
		message_dialog("The garrison assigned to Cresent Valley is small.  The few not on patrol seem joval though.", "You are glad they are here, at least Cresent Harbor is safe.");
	}
break;

beginstate 26;
	if (get_flag(2, 25) == 0) {
		set_flag(2, 25, 1);
		i = 0;
		reset_dialog();
		if (get_flag(2, 22) == 0) {
			set_flag(2, 22, 1);
			add_dialog_str(0, "The temple is quiet and peaceful.", 0);
			add_dialog_str(1, "You wonder about the placement of it.", 0);
			i = 2;
		}
		add_dialog_str(i, "A sign on the wall says:", 0);
		i = i + 1;
		if (char_ok(37))
			add_dialog_str(i, "The priest is *IN*", 10);
		else
			add_dialog_str(i, "The priest is *OUT*", 10);
		add_dialog_choice(0, "OK");
		choice = run_dialog(0);
	}
break;

beginstate 27;
	if (get_flag(2, 23) == 0) {
		set_flag(2, 23, 1);
		reset_dialog();
		add_dialog_str(0, "You have stumbled into an unusual site within the empire.", 0);
		add_dialog_str(1, "A full fledge repertoire theatre operating in the open!", 0);
		add_dialog_str(2, "A lone thespian is practicing on the stage, talking to a skull.", 0);
		choice = run_dialog(1);
	}
break;

beginstate 28;
	message_dialog("Clay and Nancy have a well read collection of novels on their bookshelf.", "You leaf through a few, but find nothing that will help your quest.");
break;
